package Lee_code;

/**
 * @author blh
 * @date 2024年08月05日 19:47
 */
public class Lee_1004_85 {
    public int longestOnes(int[] nums, int k) {
        int len = nums.length;
        int max = 0;
        int numZero = 0;
        int left = 0;
        for (int right = 0; right < len; right++) {
            if (nums[right] == 1) {
                max = Math.max(max, right - left + 1);
            } else {
                numZero++;
                if (numZero == k + 1) {
                    // 左边再跟上来
                    while (nums[left] != 0) {
                        left++;
                    }
                    left++;
                    numZero--;
                }
            }
        }
        return max;
    }
}
